package samples.duty_chain_mode.enums;

import java.util.Arrays;

public enum DutyEnum {

    MYSQL_STRATEGY(0,"MySQL", "samples.strategy_mode.strategy.MySqlStrategy"),
    INFLUXDB_STRATEGY(1,"InfluxDB", "samples.strategy_mode.strategy.InfluxDBStrategy"),
    OPC_STRATEGY(2,"OPC", "samples.strategy_mode.strategy.OPCStrategy");

    private Integer type;
    private String desc;
    /**
     * 具体策略的全限定名
     */
    private String strategy;


    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getStrategy() {
        return strategy;
    }

    public void setStrategy(String strategy) {
        this.strategy = strategy;
    }
 public static String getStrategyByType(Integer type) {
      return   Arrays.stream(values()).filter(e->e.getType().equals(type)).map(DutyEnum::getStrategy).findAny().orElseThrow(() -> new IllegalArgumentException("非法的策略类型"));
    }

    DutyEnum(Integer type, String desc, String strategy) {
        this.type = type;
        this.desc = desc;
        this.strategy = strategy;
    }
}
